package com.itlong.cloud.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.itlong.cloud.POJO.PO.DeviceBusinessChangeLogPO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.dao.ICloudIntercomOrdersDao;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.service.ICloudIntercomOrdersService;
import com.itlong.cloud.thrown.DataAccessException;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <desc>
 *      云对讲设备管理服务接口实现
 * </desc>
 *
 * @createDate 2017-11-15.
 */
@Service
public class CloudIntercomOrdersServiceImpl implements ICloudIntercomOrdersService {
    private static final Logger LOG = LoggerFactory.getLogger(CloudIntercomOrdersServiceImpl.class);
    //云对讲持久层接口

    @Autowired
    ICloudIntercomOrdersDao iCloudIntercomOrdersDao;




    /**
     * <desc>
     *     云对讲_批量保存设备端推送指令
     * </desc>
     * @param deviceBusinessChangeLogPOList
     * @return
     * @throws Exception
     * @author cuiduanwu
     * @createDate 2017-11-17
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public MessageVO saveDeviceBusinessChangeLogBatch(List<DeviceBusinessChangeLogPO> deviceBusinessChangeLogPOList) throws Exception{
        try {
            if (deviceBusinessChangeLogPOList != null&&deviceBusinessChangeLogPOList.size()>0){
                int result = iCloudIntercomOrdersDao.saveDeviceBusinessChangeLogBatch(deviceBusinessChangeLogPOList);
            }
            return  new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        }catch (Exception e){
            LOG.error("【云对讲_接收设备推送指令_保存异常】"+"\n"+ "异常数据:" + JSONObject.toJSONString(deviceBusinessChangeLogPOList));
            throw new DataAccessException("【云对讲_接收设备推送指令_保存异常】",e);
        }
    }
    /**
     * <desc>
     *     根据房间ID查询对应的楼栋与单元ID
     * </desc>
     * @param roomId
     * @return
     * @author cuiduanwu
     * @createDate 2018-1-18
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public String deviceChangeLogGetBuildAndUnitIdByRoomId(String roomId){
        return iCloudIntercomOrdersDao.deviceChangeLogGetBuildAndUnitIdByRoomId(roomId);
    }



}
